package com.inforich.web.controller.projectManage;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.inforich.common.annotation.Log;
import com.inforich.common.core.controller.BaseController;
import com.inforich.common.core.domain.AjaxResult;
import com.inforich.common.enums.BusinessType;
import com.inforich.common.utils.poi.ExcelUtil;
import com.inforich.projectManage.domain.ProjectRubbishRemoval;
import com.inforich.projectManage.dto.ProjectApproveDTO;
import com.inforich.projectManage.service.IProjectRubbishRemovalService;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 拆迁备案Controller
 *
 * @author hjm
 * @date 2022-10-30
 */
@RestController
@RequestMapping("/projectManage/projectRemoval")
public class ProjectRubbishRemovalController extends BaseController {

  @Autowired
  private IProjectRubbishRemovalService projectRubbishRemovalService;

  /**
   * 查询拆迁备案列表
   */
  @PreAuthorize("@ss.hasPermi('projectManage:projectRemoval:list')")
  @GetMapping("/list")
  public Page<ProjectRubbishRemoval> list(Page<ProjectRubbishRemoval> page,
      ProjectRubbishRemoval projectRubbishRemoval) {
    Map<String, Object> map = beanToMap(projectRubbishRemoval);
    projectRubbishRemovalService.pageProjectRubbishRemoval(page, map);
    return page;
  }


  /**
   * 导出拆迁备案列表
   */
  @PreAuthorize("@ss.hasPermi('projectManage:projectRemoval:export')")
  @Log(title = "拆迁备案", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  public void export(HttpServletResponse response, ProjectRubbishRemoval projectRubbishRemoval) {
    Map<String, Object> map = beanToMap(projectRubbishRemoval);
    List<ProjectRubbishRemoval> list = projectRubbishRemovalService.listProjectRubbishRemoval(map);
    ExcelUtil<ProjectRubbishRemoval> util = new ExcelUtil<ProjectRubbishRemoval>(
        ProjectRubbishRemoval.class);
    util.exportExcel(response, list, "拆迁备案数据");
  }

  /**
   * 获取拆迁备案详细信息
   */
  @PreAuthorize("@ss.hasPermi('projectManage:projectRemoval:query')")
  @GetMapping(value = "/{id}")
  public AjaxResult getInfo(@PathVariable("id") String id) {
    return AjaxResult.success(projectRubbishRemovalService.getProjectRubbishRemovalById(id));
  }

  /**
   * 新增拆迁备案
   */
  @PreAuthorize("@ss.hasPermi('projectManage:projectRemoval:add')")
  @Log(title = "拆迁备案", businessType = BusinessType.INSERT)
  @PostMapping
  public AjaxResult add(@Validated @RequestBody ProjectRubbishRemoval projectRubbishRemoval) {
    return toAjax(projectRubbishRemovalService.save(projectRubbishRemoval));
  }

  /**
   * 修改拆迁备案
   */
  @PreAuthorize("@ss.hasPermi('projectManage:projectRemoval:edit')")
  @Log(title = "拆迁备案", businessType = BusinessType.UPDATE)
  @PutMapping
  public AjaxResult edit(@Validated @RequestBody ProjectRubbishRemoval projectRubbishRemoval) {
    return toAjax(projectRubbishRemovalService.updateById(projectRubbishRemoval));
  }

  /**
   * 删除拆迁备案
   */
  @PreAuthorize("@ss.hasPermi('projectManage:projectRemoval:remove')")
  @Log(title = "拆迁备案", businessType = BusinessType.DELETE)
  @DeleteMapping("/{ids}")
  public AjaxResult remove(@PathVariable String[] ids) {
    return toAjax(projectRubbishRemovalService.removeByIds(Arrays.asList(ids)));
  }

  /**
   * 审批
   */
  @PreAuthorize("@ss.hasPermi('projectManage:projectRemoval:approve')")
  @PostMapping("/approve")
  public AjaxResult approve(@Validated @RequestBody ProjectApproveDTO projectApproveDTO) {
    return projectRubbishRemovalService.approve(projectApproveDTO);
  }
}
